﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace XWord.WPF.ApplicationFramework
{
    public interface ISearch
    {
        object SearchObject { get; set; }

        bool CanQuery();

        void BeginQuery(ref IEnumerable Target);

        IEnumerable Query();
    }

    public class BaseSearch:ISearch
    {
       

        public object SearchObject { get; set; }

     

        public virtual bool CanQuery()
        {
            return true;
        }

        public virtual IEnumerable Query()
        {
            return null;
        }

        public void BeginQuery(ref IEnumerable Target)
        {
            if (CanQuery())
            {
                Target = Query();
            }
        }

    }

    public class SearchFactory
    {
        public static T CreateSearchObject<T>(object SearchObject) where T:ISearch
        {
            var search = Activator.CreateInstance<T>();
            search.SearchObject = SearchObject;
            return search;
        }
    }
}